
const blogTypeModel = require('../model/blogTypeModel');

module.exports.getBlogTypeListDao = async function () {
  return await blogTypeModel.findAll({
    order: [['order', 'ASC']]
  })
}

module.exports.addBlogTypeDao = async function (blogType) {
  return await blogTypeModel.create(blogType)
}

module.exports.delBlogTypeByIdDao = async function (id) {
  await blogTypeModel.destroy({
    where: {
      id
    }
  })
}

module.exports.updateBlogTypeDao = async function (id, blogType) {
  await blogTypeModel.update(blogType, {
    where: {
      id
    }
  })
  return await blogTypeModel.findByPk(id)
}

module.exports.getBlogTypeByIdDao = async function (id) {
  return await blogTypeModel.findByPk(id)
}

module.exports.addBlogTypeNumDao = async function (id) {
  let blogType = await blogTypeModel.findByPk(id)
  blogType.articleCount++
  await blogType.save()
  return blogType
}